package com.zslc.securitymonitoring.controller;

import com.zslc.securitymonitoring.vo.GlobalSeverityStatistic;
import com.zslc.securitymonitoring.service.AlarmTypeService;
import com.zslc.securitymonitoring.util.ResultCMS;
import com.zslc.securitymonitoring.vo.GlobalSeverityVO;
import com.zslc.securitymonitoring.vo.RegionStatistic;
import com.zslc.securitymonitoring.vo.UrlStatistic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * 过去六个月告警类型分布
 *
 * @author Gyc
 */
@Slf4j
@RestController
@RequestMapping("/alarm")
public class AlarmTypeController {
    @Autowired
    private AlarmTypeService alarmTypeService;

    /**
     * 过去六个月告警总览统计
     *
     * @return com.zslc.securitymonitoring.util.ResultCMS
     * @author Gaoyc
     * @date 2024/06/12 13:59
     */
    @GetMapping("/severity/statistic")
    public ResultCMS severityStatistic() {
        try {
            Map<String, List<GlobalSeverityStatistic>> resultMap = alarmTypeService.severityStatisticBy6Month();
            return ResultCMS.success(resultMap);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return ResultCMS.fail_5000();
        }
    }


    /**
     * 过去六个月告警类型分布统计
     *
     * @return com.zslc.securitymonitoring.util.ResultCMS
     * @author Gaoyc
     * @date 2024/06/12 14:01
     */
    @GetMapping("/type/statistic")
    public ResultCMS typeStatistic() {
        try {
            List<Map<String, Object>> list = alarmTypeService.typeStatisticBy6Month();
            return ResultCMS.success(list);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return ResultCMS.fail_5000();
        }
    }

    /**
     * 30天内报警数量top10
     * @return com.zslc.securitymonitoring.util.ResultCMS
     * @author Gaoyc
     * @date 2024/06/13 20:45
     */
    @GetMapping("/url/statistic")
    public ResultCMS urlStatistic() {
        try {
            List<UrlStatistic> list = alarmTypeService.urlStatisticBy30Day();
            return ResultCMS.success(list);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return ResultCMS.fail_5000();
        }
    }

    @GetMapping("/region/statistic")
    public ResultCMS regionStatistic() {
        try {
            List<RegionStatistic> list = alarmTypeService.regionStatistic();
            return ResultCMS.success(list);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return ResultCMS.fail_5000();
        }
    }



}
